<HTML><HEAD><TITLE>setenv(+Name, +Value)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Operating System</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>setenv(+Name, +Value)</H1>
Sets the environment variable Name to the given value
<DL>
<DT><EM>Name</EM></DT>
<DD>String or atom.
</DD>
<DT><EM>Value</EM></DT>
<DD>String, atom or number.
</DD>
</DL>
<H2>Description</H2>
    The first argument must be a string or an atom and is taken as the
    name of an operating system environment variable.  The value of this
    environment variable is set, or changed to, the new value Value.
<P>
    When Value is an atom or number, it is first converted to a string,
    and the environment variable is set to the resulting string value.
<P>
    The mechanism can be used to pass information from an eclipse-process
    to its sub-processes.  Note however, that due to operating system
    limitations, environment strings cannot contain null characters
    (unlike ECLiPSe strings).  Also, the strings used as arguments to
    setenv/2 cannot be garbage collected and will accumulate.
<P>
    Operating system dependencies: Because of portability issues, on UNIX
    there is currently no facility to unset an environment variable
    completely, but it can set to an empty string. On Windows on the other
    hand, an environment variable's value cannot be the empty string:
    setting an environment variable to the empty string makes it
    indistinguishable from an unset or nonexisting one.

<H3>Modes and Determinism</H3><UL>
<LI>setenv(+, +) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Name or Value is not instantiated.
<DT><EM>(5) type error </EM>
<DD>Name is instantiated, but not to a string or an atom.
<DT><EM>(5) type error </EM>
<DD>Value is instantiated, but not to a string, atom or number.
<DT><EM>(170) system interface error </EM>
<DD>The environment could not be changed
</DL>
<H2>Examples</H2>
<PRE>
   ?- setenv(abc, hello), getenv(abc, X).
   X = "hello"
   Yes (0.00s cpu)

   ?- setenv("abc", "world"), getenv(abc, X).
   X = "world"
   Yes (0.00s cpu)

   ?- setenv(abc, 999), getenv(abc, X).
   X = "999"
   Yes (0.00s cpu)

   ?-  setenv(abc, data), sh("echo $abc").
   data
   Yes (0.00s cpu)

   ?- setenv(abc, data), exec([sh,"-c","echo $abc"], []).
   data
   Yes (0.00s cpu)

   ?- setenv(abc, data), exec([eclipse,"-e","getenv(abc,X),writeln(X)"], []).
   data
   Yes (0.00s cpu)

   ?- setenv(abc, ""), getenv(abc, X).	% on UNIX
   X = ""
   Yes (0.00s cpu)

   ?- setenv(abc, ""), getenv(abc, X).	% on Windows
   No (0.00s cpu)
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/opsys/exec-2.html">exec / 2</A>, <A HREF="../../kernel/opsys/exec-3.html">exec / 3</A>, <A HREF="../../kernel/opsys/getenv-2.html">getenv / 2</A>, <A HREF="../../kernel/opsys/sh-1.html">sh / 1</A>
</BODY></HTML>
